package com.kili.cloud.common.springfox;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @description:整合Springfox和Swagger-ui生成API文档
 * @author: tom.liu
 * @date: 2019/6/13 19:54
 */
@Configuration
@EnableSwagger2
public class Swagger2 {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                //所有controller
                .apis(RequestHandlerSelectors.basePackage("com.kili.cloud.shorturl.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * @description: 构建ApiInfo
     * @author: tom.liu
     * @date: 2019/6/20 18:47
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                //页面标题
                .title("Spring Cloud微服务API")
                //创建人
                .contact(new Contact("kilimall", "http://com.kili.co", ""))
                //版本号
                .version("1.0")
                //描述
                .description("API 描述")
                .build();
    }
}
